package com.yh.dao.impl;

import com.yh.dao.IPersonDao;
import com.yh.entity.Person;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Getter
@Setter
@Repository("personDaoImpl")
public class PersonDaoImpl extends HibernateTemplate implements IPersonDao {
    @Autowired
    @Qualifier("sessionFactory")
    private SessionFactory sessionFactory;
    @Override
    public List getAllPerson() {
        return find("from Person") ;
    }

    @Override
    public void addPerson(Person p) {
         save(p);
    }

    @Override
    public Person login(Person p) {
        List<Person> list=find("from Person where uname=? and upwd=?",p.getUname(),p.getUpwd());
        return list.size()>0?list.get(0):null;

    }
}
